{template 'common/header'}
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/css/style.css" />
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<style>
    #pcontents {line-height: 30px;}
    #psortlist li {width: 420px;display: inline-block;margin-left: 1%;  }
    .photos .control-label {height: 25px;line-height: 25px;  }
    #templist a {margin-bottom: 5px;}
    #templist a.btn + a.btn, #sysvar a.btn + a.btn {margin-left: 0px;  }
    #userlist li{  width: 130px;  overflow: hidden;  }
    #userlist li img{  width: 130px;}
    .messagestep{  width: 33%;  float: left;  padding: 5px;  }
    #opstep  canvas, #opstep  img{  max-width: 100%;  }
    #userlist li{  float: left;  margin-right: 5px;  }
    #userlist li  .input-group-addon{  font-size: 12px;  }
</style>
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">
            {$xtitle}
        </h3>
    </div>
    <div class="panel-body">
        {template 'old/Web/menu'}
        <form class="form-horizontal form-label-left input_mask" method="post" action="{php echo $this->createWebUrl('Web', array('op'=>'saveonline'));}" id="xc_form">
            <input type="hidden" name="xkey" value="{$keyval}">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">URL</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    <input type="text" class="form-control" value="{php echo $_W['siteroot'] . 'app/'.substr($this->createWebUrl('online'),2);}" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">Token</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    <input type="text" class="form-control" placeholder="Token" name="token" value="{$xc[token]}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">默认回复</label>
                <div class="col-xs-12 col-sm-8" style="position: relative;">
                    {if $xc['reply_status']==1}
                    <input type="checkbox" checked class="js-switch" value="1" name="reply_status">
                    {else}
                    <input type="checkbox" class="js-switch" name="reply_status" value="1">
                    {/if}
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">回复内容</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    <input type="text" class="form-control" placeholder="回复内容" name="reply_content" value="{$xc[reply_content]}">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">消息刷新间隔</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    <input type="text" class="form-control" placeholder="消息刷新间隔（单位：秒）" name="refresh" value="{$xc[refresh]}">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">模板发送间隔</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    <input type="text" class="form-control" placeholder="发送间隔（单位：秒）" name="jiange" value="{$xc[jiange]}">
                </div>
            </div>
            <div class="form-group" id="radmessage">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">通知模板</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    <div class="btn-group" id="templist">
                    </div>
                    <div class="row" id="ieaples">
                    </div>

                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">系统变量</label>
                <div class="col-md-10 col-sm-9 col-xs-12">


                    <div class="btn-group" id="sysvar" style="background-color: white;">

                        {loop $mobalarrr $xkey $xval}
                        <a class="btn btn-default" data-value="{$xkey}">{$xval}</a>
                        {/loop}
                        <br>
                        <br>
                        备注：如果要插入到某个属性下面，就选择光标定位到指定属性
                    </div>
                    <!--{{xcsys_time}} 当前时间 例如： 2017/12/13 05:30:20-->
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">系统变量说明</label>
                <div class="col-md-10 col-sm-9 col-xs-12" id="sysreadme">

                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">模板内容字体</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    <div class="input-group">
                        <input class="form-control" type="text" name="xc[topcolor]"
                               placeholder="请选择颜色" value="{$xc['xc']['topcolor']}">
                                            <span class="input-group-addon"
                                                  style="width:35px;border-left:none; background-color:{$xc['xc']['topcolor']} "></span>
                                            <span class="input-group-btn">
                <button class="btn btn-default colorpicker" type="button">选择颜色 <i class="fa fa-caret-down"></i></button>
                <button class="btn btn-default colorclean" type="button"><span><i
                        class="fa fa-remove"></i></span></button>
                 </span>
                    </div>

                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">模版消息跳转链接</label>
                <div class="col-xs-12 col-sm-8">
                    <input type="text" name="xc[url]" class="form-control parafrom"
                           value="{$xc['xc']['url']}"
                           placeholder="对应参数用[可以为空]例如{{url}}"/>
                    <br> 跳转网址[开启跳转网址后小程序失效]
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">开启小程序</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    {if $xc['xc']['ismin']==1}
                    <input type="checkbox" class="js-switch" value="1" checked name="xc[ismin]"
                           data-value="{$xc['xc']['ismin']}">
                    {else}
                    <input type="checkbox" class="js-switch" value="1" name="xc[ismin]"
                           data-value="{$xc['xc']['ismin']}">
                    {/if}
                    <br>
                    <br>
                    【如果使用小程序，小程序必须跟公众号关联,否则无法使用小程序】

                </div>
            </div>
            <div id="ismin">
                <div class="form-group">
                    <label class="control-label col-md-2 col-sm-3 col-xs-12">小程序appid</label>
                    <div class="col-md-10 col-sm-9 col-xs-12">
                        <input type="text" name="xc[miniprogramappid]" class="form-control parafrom"
                               value="{$xc['xc']['miniprogramappid']}"
                               placeholder="对应参数用[可以为空]例如{{minappid}}"/>
                        <br> 对应参数例如

                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-md-2 col-sm-3 col-xs-12">小程序参数</label>
                    <div class="col-md-10 col-sm-9 col-xs-12">
                        <input type="text" name="xc[miniprogrampagepath]"
                               class="form-control parafrom"
                               value="{$xc['xc']['miniprogrampagepath']}"
                               placeholder="对应参数用[可以为空][index?foo=bar]例如{{pagepath}}"/>
                        <br> 对应参数例如 xx/pages/index?id={xid};
                    </div>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">模板</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    <input type="hidden" name="xc[template_example]" class="form-control"
                           value="{$xc['template_example']}"/>
                    <input type="hidden" name="xc[template_name]" class="form-control"
                           value="{$xc['template_name']}"/>
                    <input type="text" name="xc[template_id]" class="form-control"
                           value="{$xc[xc]['template_id']}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">属性</label>
                <div class="col-md-10 col-sm-9 col-xs-12" id="pttt">

                    {loop $xc['data'] $xkey $xval}
                    <div class="row row-fix">
                        <div class="col-xs-7 col-sm-7" style="padding-right:0;">
                                <textarea class="form-control parafrom" type="text" name="data[{$xkey}][value]"
                                          placeholder="{$xkey}可以使用參數里的变量[可以为空]例如{{phone}}">{$xval['value']}</textarea>
                        </div>
                        <div class="col-xs-5 col-sm-5" style="padding-right:0;">
                            <div class="input-group">
                                <input class="form-control" type="text" name="data[{$xkey}][color]"
                                       placeholder="请选择颜色" value="{$xval['color']}">
                                                    <span class="input-group-addon"
                                                          style="width:35px;border-left:none;background-color:{$xval['color']}"></span>
                                                    <span class="input-group-btn">
                <button class="btn btn-default colorpicker" type="button">选择颜色 <i class="fa fa-caret-down"></i></button>
                <button class="btn btn-default colorclean" type="button"><span><i
                        class="fa fa-remove"></i></span></button>
                 </span>
                            </div>
                        </div>
                    </div>
                    {/loop}


                </div>
            </div>

            <div class="form-group" style="display: none" id="stepcontents">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">操作步骤</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    <div id="opstep">
                    </div>

                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2 col-sm-3 col-xs-12">信息接受人</label>
                <div class="col-md-10 col-sm-9 col-xs-12">
                    <ul id="userlist">

                        {loop  $xc["userlist"] $uxkey $uxval}
                        <li data-openid="{$uxval['openid']}" data-nickname="{$uxval['nickname']}" data-headimgurl="{$uxval['headimgurl']}" ><img src="{$uxval['headimgurl']}">

                            <div class="input-group">
                                <span class="input-group-btn"> <button  class=" btn btn-default" type="button"><span><i class="fa fa-remove"></i></span></button></span>
                                <span class="input-group-addon" style="width:100px;border-left:none;overflow: hidden;">{$uxval['nickname']}</span>

                            </div>
                        </li>
                        {/loop}
                    </ul>
                    <div style="clear: both;"></div>
                    <button type="button" class="btn btn-default"  id="btnop">增加接受人员</button>
                </div>
            </div>
            <script>
                var parameter = {
                    parameter_add: function (objc) {
                        $(objc).parent().after('<li class="input-group"> <input type="text" class="form-control"  data-name="attr"value=""> <input type="text" class="form-control" data-name="value" value=""> <span class="input-group-btn" onclick="parameter.parameter_add(this)"> <button class="btn btn-default" type="button"><i class="fa fa-plus"></i></button> </span> <span class="input-group-btn" onclick="parameter.parameter_del(this)"> <button class="btn btn-danger" type="button"><i class="fa fa-remove"></i></button> </span></li>');
                    },
                    parameter_del: function (objc) {
                        if ($(objc).parent().siblings().length > 0) {
                            $(objc).parent().remove();
                        }
                    }
                }
            </script>
            <div class="form-group testphone">
                <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">手机号</label>
                <div class="col-xs-12 col-sm-8" style="position: relative;">
                    <div class="input-group ">
                                        <span class="input-group-btn">
                            <button class="btn btn-default" id="btnmessagetest" type="button">短信测试</button>
                        </span>
                    </div>
                </div>
            </div>
            <div class="form-group xc_btn_row"  >
                <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-5 col-sm-offset-5  col-md-xs-5 ">
                    <button type="button" class="btn btn-primary" id="btsave">确认</button>
                    <a type="button" class="btn btn-default"  href="{php echo $this->createWebUrl('Web', array('op'=>'edit','xtitleb'=> urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea)));}" >返回</a>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        function insertAtCursor(myField, myValue) {
            //IE 浏览器
            if (document.selection) {
                myField.focus();
                sel = document.selection.createRange();
                sel.text = myValue;
                sel.select();
            }
            //FireFox、Chrome等
            else if (myField.selectionStart || myField.selectionStart == '0') {
                var startPos = myField.selectionStart;
                var endPos = myField.selectionEnd;

                // 保存滚动条
                var restoreTop = myField.scrollTop;
                myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);

                if (restoreTop > 0) {
                    myField.scrollTop = restoreTop;
                }

                myField.focus();
                myField.selectionStart = startPos + myValue.length;
                myField.selectionEnd = startPos + myValue.length;
            } else {
                myField.value += myValue;
                myField.focus();
            }
        }
        function isminstatut() {

            if ($('[name="xc[ismin]"]').is(":checked")) {
                $("#ismin").show();
            }
            else {
                $("#ismin").hide();
            }
        }
        setTimeout(function () {
        }, 100)
        actobjx = null;
        var teljson = {$idata["content"]};
        var guzhuer = '{$idata["erurl"]}';
        var $mesaurl= {$mesaurl}


        function userlistupdate() {
            if($mesaurl["ident"]!="")
            {
                var $postmodel= {};
                $postmodel["ident"]=  $mesaurl["ident"];
                $.ajax({
                    type: "post",
                    url: "{php echo $this->createWebUrl('Web', array('op'=>'getnewuserlist'));}",
                    dataType: "json",
                    data: $postmodel,
                    success: function (msg) {


                        if(msg["obj"].length>0){
                            var phtml=[];
                            for(var i=0;i<msg["obj"].length;i++)
                            {

                                phtml.push("<li  data-openid='"+msg["obj"][i]["openid"]+"' data-headimgurl='"+msg["obj"][i]["headimgurl"]+"' data-nickname='"+msg["obj"][i]["nickname"]+"'>")
                                phtml.push("<img src='"+msg["obj"][i]["headimgurl"]+"'>");

                                phtml.push('<div class="input-group">');
                                phtml.push(' <span class="input-group-btn">    <button  class=" btn btn-default" type="button"><span><i class="fa fa-remove"></i></span></button></span>');
                                phtml.push('<span class="input-group-addon" style="width:100px;border-left:none;overflow: hidden;">'+msg["obj"][i]["nickname"]+'</span>');
                                phtml.push(' </div>');

                                phtml.push("</li>")


                            }

                            $("#userlist").append(phtml.join(""));
                        }


                    }
                });
            }
        }

        //ident
        $(function () {
            $("body").on("focus", ".parafrom", function () {
                actobjx = $(this).get(0);
            })


            $("#userlist").on("click","button",function () {


                $(this).closest("li").remove();

            })


            var autouser=-1;
            $("#btnop").click(function () {
                $("#stepcontents").show();
                userlistupdate();
                if(autouser==-1)
                {
                    autouser=1;
                    setInterval(function () {
                        userlistupdate()
                    },1000)
                }
            })



            $("#sysvar a").click(function () {
                if ($("#templist").find(".btn-primary").length < 1) {
                    swal({
                        text: "请选择通知模版",
                        type: "error",
                        timer: 3000,
                        confirmButtonText: '关闭'
                    })
                    return;
                }
                if (actobjx == null) {
                    actobjx = $(".parafrom").eq(0).get(0);
                }
                insertAtCursor(actobjx, "{{" + $(this).attr("data-value") + "}}")
            })
            var itop = $("#sysvar").offset().top - $("#radmessage").offset().top;

            function autopos() {
                var topScroll = document.documentElement.scrollTop || document.body.scrollTop;
                // var topScroll =document.body.scrollTop;//滚动的距离,距离顶部的距离
                var bignav = document.getElementById("sysvar");//获取到导航栏id
                if (topScroll > itop) {  //当滚动距离大于250px时执行下面的东西
                    bignav.style.position = 'fixed';
                    bignav.style.top = '0';
                    bignav.style.zIndex = '9999';
                } else {//当滚动距离小于250的时候执行下面的内容，也就是让导航栏恢复原状
                    bignav.style.position = 'static';
                }
            }
            window.onscroll = function (e) {
                autopos();
            }
            $("#xc_form").bind("keydown", "input", function (e) {
                // 兼容FF和IE和Opera
                var theEvent = e || window.event;
                var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
                if (code == 13) {
                    //回车执行查询
                    $("#btsave").click();
                }
            });

            $('[name="xc[ismin]"]').change(function () {
                isminstatut();
            })

            $(".xselect").each(function () {

                if ($(this).attr("data-value") !== "") {
                    $(this).find("option[value='" + $(this).attr("data-value") + "']").attr("selected", "selected");
                }
            })
            isminstatut()


            if (teljson != null && teljson["template_list"].length > 0) {

                for (var i = 0; i < teljson["template_list"].length; i++) {
                    var $model = $('<a   class="btn btn-default" data-value="' + teljson["template_list"][i]['template_id'] + '">' + teljson["template_list"][i]['title'] + '</a>');
                    $model.data("template", teljson["template_list"][i]);
                    $("#templist").append($model)
                }
            }


            $("#templist a").click(function () {

                $(this).addClass("btn-primary");
                $(this).siblings().removeClass("btn-primary");
                $pdata = $(this).data("template");
                $('[name="xc[template_id]"]').val($pdata["template_id"]);
                $('[name="xc[template_name]"]').val($pdata["title"]);
                $temobj = $pdata;
                $("#ieaples").empty();
                var template_exampledata = $temobj["content"].replace(/\n/g, "<br/>")
                $("#ieaples").html(template_exampledata)
                $('[name="xc[template_example]"]').val(template_exampledata);

                var str = $temobj["content"];
                var r = /\{{(.+?)\}}/g;
                var mydadta = str.match(r);
                $("#pttt").empty();
                if (mydadta != null) {
                    for (var i = 0; i < mydadta.length; i++) {
                        $kvalue = mydadta[i];
                        $kvalue = $kvalue.replace("{{", "");
                        $kvalue = $kvalue.replace("}}", "");
                        $mydat = initselsct($kvalue);
                        $("#pttt").append($mydat);
                    }

                }
                $(".colorpicker").each(function () {
                    var elm = this;
                    util.colorpicker(elm, function (color) {
                        $(elm).parent().prev().prev().val(color.toHexString());
                        $(elm).parent().prev().css("background-color", color.toHexString());
                    });
                });
                $(".colorclean").click(function () {
                    $(this).parent().prev().prev().val("");
                    $(this).parent().prev().css("background-color", "#FFF");
                });
            })

            $(".colorpicker").each(function () {
                var elm = this;
                util.colorpicker(elm, function (color) {
                    $(elm).parent().prev().prev().val(color.toHexString());
                    $(elm).parent().prev().css("background-color", color.toHexString());
                });
            });
            $(".colorclean").click(function () {
                $(this).parent().prev().prev().val("");
                $(this).parent().prev().css("background-color", "#FFF");
            });
            $xtemplate_id = $("[name='xc[template_id]']").val();
            if ($xtemplate_id != "") {
                var $actojb = $("#templist").find('[data-value="' + $xtemplate_id + '"]');
                $actojb.addClass("btn-primary");
                //   $("#templist").find('[data-value="'+$xtemplate_id+'"]').addClass("btn-primary");
                $temobj = $actojb.data("template");
                $("#ieaples").empty();
                if($temobj)
                {
                    $("#ieaples").html($temobj["content"].replace(/\n/g, "<br/>"))
                }
            }

            var xpagecss = {
                xload: function () {
                    swal({
                        title: "操作中",
                        text: "",
                        imageUrl: "../addons/{php echo $_GPC['m']}/resource/images/xload1.gif",
                        showConfirmButton: false,
                        allowOutsideClick: true
                    });
                },
                close: function () {
                    swal.close();
                }
            }
            var replyrdata = {};
            replyrdata[1] = "success";
            replyrdata[-1] = "error";
            replyrdata[2] = "warning";
            replyrdata[3] = "info";
            replyrdata[4] = "question";
            function message(data) {
                $mesoption = {};
                if (data["status"] === 1) {
                    if ($('[name="id"]').val() == "" || $('[name="id"]').val() == "0") {
                        form.reset();
                    }
                    $mesoption["timer"] = 1000;
                    $mesoption["type"] = replyrdata[data["status"]];
                }
                $mesoption["title"] = data["message"];
                $mesoption["text"] = data["message"];
                swal($mesoption);
            }


            function initselsct($col) {
                var $colname = $col.replace(".DATA", "");
                var myconts = '<div class="row row-fix">' +
                        '<div class="col-xs-7 col-sm-7" style="padding-right:0;">' +
                        '<textarea class="form-control parafrom" type="text" name="data[' + $colname + '][value]" placeholder="' + $col + ',对应POST或GET里的参数  xx{{phone}}"  ></textarea>' +
                        '</div>' +
                        ' <div class="col-xs-5 col-sm-5" style="padding-right:0;">' +
                        ' <div class="input-group">' +
                        ' <input class="form-control" type="text" name="data[' + $colname + '][color]" placeholder="请选择颜色" value="">' +
                        ' <span class="input-group-addon" style="width:35px;border-left:none;"></span>' +
                        ' <span class="input-group-btn">' +
                        '<button class="btn btn-default colorpicker" type="button">选择颜色 <i class="fa fa-caret-down"></i></button>' +
                        '<button class="btn btn-default colorclean" type="button"><span><i class="fa fa-remove"></i></span></button>' +
                        ' </span>' +
                        '</div>' +
                        ' </div>' +
                        ' </div>'
                return myconts;
            }


            $strreadmecontents = [];
            paras = [];
            $("#sysvar").find("a").each(function () {
                //   console.log($(this).html());
                paras.push($(this).attr("data-value"));
                $strreadmecontents.push("{{" + $(this).attr("data-value") + "}} -" + $(this).html())
                //  console.log("{{"+ $(this).attr("data-value")+"}}-" +$(this).html());
            })

            if ($("[name='xc[para]']").val() == "") {
                $("[name='xc[para]']").val(paras.join(","));
            }
            $("#sysreadme").append($strreadmecontents.join(","));

        });


        function messagecontestn() {
            $ckeckvalue = $('[name="type"]:checked').val();
            $(".radiocontents").hide();
            $(".radiocontents").eq($ckeckvalue - 1).show();
            if ($ckeckvalue == "1" || $ckeckvalue == "2") {
                $("#mobile").show();
                $(".type1,.type2").hide();
                $(".type" + $ckeckvalue).show();
            }
            else {
                $(".type1,.type2").hide();
                $("#mobile").hide();
            }

        }

        function  opstepfun() {

            require(["jquery",'jquery.qrcode'], function ($, util) {
                var  $htmlcontents=[];

                $htmlcontents.push("<div  class='messagestep'>");
                if(guzhuer=="")
                {
                    $htmlcontents.push("<h2>暂未设定关注的公众号,如果你已经关注公众号请进行下一步,如果没有关注公众号请先关注公众号</h2>")
                }
                else
                {
                    $htmlcontents.push('第一步：如果未关注公众号请先扫码关注公众号【下面二维码】<br/><img src="'+guzhuer+'" width="230">');
                }
                $htmlcontents.push("</div>");
                $htmlcontents.push("<div  class='messagestep'>");
                if($mesaurl["url"]!="")
                {
                    $htmlcontents.push('第二步扫描下面二维码 <div id="er2" url="'+$mesaurl["url"]+'" width="230"></div> ');

                }
                $htmlcontents.push("</div>");

                $htmlcontents.push("<div  class='messagestep'>确认保存</div>");
                $("#opstep").append($htmlcontents.join(""));

                $("#er2").html('').qrcode({
                    render: 'canvas',
                    width: 230,
                    height: 230,
                    text: $mesaurl["url"]
                });

            })





        }
        $(function () {
            opstepfun();

            messagecontestn();
            $('[name="type"]').change(function () {
                messagecontestn();
            })

            $("#btnmessagetest").click(function () {

                $actfrom = $("#xc_form");
                var $serdata = $actfrom.serializeArray();
                $postmodel = {};
                for (var i = 0; i < $serdata.length; i++) {
                    $postmodel[$serdata[i]["name"]] = $serdata[i]["value"];

                }
                $('#xc_form').find('[type="checkbox"]').not(":checked").each(function () {
                    $postmodel[$(this).attr("name")]=-1;
                    //  $postdate = $postdate + "&" + $(this).attr("name") + "=-1";
                })

                $("ul.parameter").each(function () {
                    var parametermdoel = [];
                    $(this).find("li").each(function () {
                        var parameter_li = {};
                        $(this).find("input").each(function () {
                            if ($.trim($(this).val()) != "") {
                                parameter_li[$(this).attr("data-name")] = $(this).val();
                            }
                        })
                        parametermdoel.push(parameter_li);
                    })
                    $postmodel[$(this).attr("data-field")] = parametermdoel;
                })

                $userlist=[];
                $("#userlist").find("li").each(function () {
                    var tmodel={};

                    tmodel["openid"]=$(this).attr("data-openid");
                    tmodel["headimgurl"]=$(this).attr("data-headimgurl");
                    tmodel["nickname"]=$(this).attr("data-nickname");
                    $userlist.push(tmodel);
                })
                $postmodel["userlist"]=$userlist;

                $.ajax({
                    type: $actfrom.attr("method"),
                    url: "{php echo $this->createWebUrl('Web', array('op'=>'testsmsv2'));}",
                    dataType: "json",
                    data: $postmodel,
                    success: function (msg) {
                        message(msg)
                    }
                });
            })

        })


        //现在只在状态这里使用
        var xvalidator = null;

        $("#btsave").click(function () {
            $brvalue =true;
            if ($brvalue) {


                if ($('[name="type"]:checked').val() == 3) {
                    if ($("#templist").find(".btn-primary").length < 1) {
                        util.message('请选择通知模板.');
                        return false;
                    }
                }


                xajaxfrom("#xc_form");
            }
            return false;
        })

        function message(data) {
            $mesoption = {};
            if (typeof(data["title"]) == "undefined") {
                $mesoption["title"] = data["message"];
            }
            else {
                $mesoption["title"] = data["title"];
            }
            $mesoption["text"] = data["message"];
            swal($mesoption);
        }
        function xajaxfrom(form) {
            $actfrom = $(form);
            var $serdata = $actfrom.serializeArray();
            $postmodel = {};
            for (var i = 0; i < $serdata.length; i++) {
                $postmodel[$serdata[i]["name"]] = $serdata[i]["value"];

            }
            $('#xc_form [type="checkbox"]:not(":checked")').each(function () {
                $postmodel[$(this).attr("name") ] = -1;
                //     $postdate = $postdate + "&" + $(this).attr("name") + "=-1";
            })
            $("ul.parameter").each(function () {
                var parametermdoel = [];
                $(this).find("li").each(function () {
                    var parameter_li = {};
                    $(this).find("input").each(function () {
                        if ($.trim($(this).val()) != "") {
                            parameter_li[$(this).attr("data-name")] = $(this).val();
                        }
                    })
                    parametermdoel.push(parameter_li);
                })
                $postmodel[$(this).attr("data-field")] = parametermdoel;
            })
            $userlist=[];
            $("#userlist").find("li").each(function () {
                var tmodel={};
                tmodel["openid"]=$(this).attr("data-openid");
                tmodel["headimgurl"]=$(this).attr("data-headimgurl");
                tmodel["nickname"]=$(this).attr("data-nickname");
                $userlist.push(tmodel);
            });
            $postmodel["userlist"]=$userlist;
            $.ajax({
                type: $actfrom.attr("method"),
                url: $actfrom.attr("action"),
                dataType: "json",
                data: $postmodel,
                success: function (msg) {
                    message(msg)
                }
            });
        }
    });
</script>
{template 'common/footer'}